package com.e.Adapter;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.e.Dao.UserDao;
import com.e.Pojo.Order;
import com.e.Pojo.User;
import com.e.SQL.UserDBHepler;
import com.e.ticket.R;

import java.util.List;

public class OrderAdapter extends BaseAdapter {

    private List<Order> orderList;
    private Context ctr;
    private LayoutInflater inflater;
    private UserDao userDao;

    public OrderAdapter(Context context,List<Order> list){
        ctr = context;
        this.orderList = list;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return orderList.size();
    }

    @Override
    public Object getItem(int i) {
        return orderList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        Order order = orderList.get(i);
        ViewHolder viewHolder = null;
        if(view==null){
            view = inflater.inflate(R.layout.order_item,viewGroup,false);
            viewHolder = new ViewHolder();
            viewHolder.start = (TextView) view.findViewById(R.id.order_start);
            viewHolder.end = (TextView) view.findViewById(R.id.order_end);
            viewHolder.time = (TextView) view.findViewById(R.id.order_time);
            viewHolder.sname = (TextView) view.findViewById(R.id.order_sname);
            viewHolder.orderId = (TextView) view.findViewById(R.id.order_id);
//            viewHolder.btn_cancel = (Button) view.findViewById(R.id.order_cancel);
            view.setTag(viewHolder);
        }else{
            viewHolder =(ViewHolder) view.getTag();
        }
        viewHolder.start.setText(order.getStart());
        viewHolder.end.setText(order.getLast());
        viewHolder.time.setText(order.getDate1());
        viewHolder.sname.setText(order.getSname());
        viewHolder.orderId.setText(""+order.getId());
//        viewHolder.btn_cancel.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                   userDao = new UserDao(new UserDBHepler(view.getContext()));

//            }
//        });
        return view;
    }

    static class ViewHolder{
        public TextView start;
        public TextView end;
        public TextView time;
        public TextView sname;
        public TextView orderId;
    }
}
